package io.github.hadyang.leetcode.offer;

import org.junit.Test;

/** @author haoyang.shi */
public class NumberOfOne {

  @Test
  public void test() {
    System.out.println(NumberOf1(3));
    System.out.println(NumberOf1(-3));
  }

  public int NumberOf1(int n) {
    int mask = 0x01;

    int res = 0;
    int t = n;
    while (t != 0) {
      if ((t & mask) == 1) {
        res++;
      }
      t = t >>> 1;
    }

    return res;
  }
}
